

#include "Public.h"


UR_FIFO_TY str_ur_fifo;


void ur_fifo_init(void)
{
	memset(&str_ur_fifo,0,sizeof(str_ur_fifo));
}


u8 ur_fifo_insert(u8 queue_data)
{
	if((str_ur_fifo.tail + 1) % QUEUE_BUF_SIZE == str_ur_fifo.head)
	{
		//input queue overflowing
		return 0;
	} 
	str_ur_fifo.buf[str_ur_fifo.tail] = queue_data;

	str_ur_fifo.tail = (str_ur_fifo.tail + 1) % QUEUE_BUF_SIZE;

	return 1;
}


u8 ur_fifo_retrieve(u8 *queue_data)
{
	*queue_data = 0;
	
	if(str_ur_fifo.head == str_ur_fifo.tail)
	{
		// output queue is empty	
		return 0;
	}

	*queue_data = str_ur_fifo.buf[str_ur_fifo.head];
	
	str_ur_fifo.head = (str_ur_fifo.head + 1) % QUEUE_BUF_SIZE;

	return 1;
}

u8 ur_fifo_is_empty(void)
{
	if(str_ur_fifo.tail == str_ur_fifo.head)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}








